// subPages/business/goods/goods.js
const app = getApp();
var util =  require('../../../utils/util.js');
var json =  require('../../../data/json.js');
var loadMoreView,p = 1,num = app.globalData.pageNum,type = 'goods'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leftNavList:[],
    goodsNavList:[{class_name: '全部商品'}],
    navItemCurr:0,
    currentGoodsNav: 0,
    currentNav: 0,
    classId: '',
    currentId: '',
    mainType: 1,
    tabList:[
      {
          id: 0,
          name: '本周菜谱'
      },{
          id: 1,
          name: '下周菜谱'
      }
    ],
    themeColor: app.globalData.themeColor,
    downImg: '/resources/business/down.png',
    upImg: '/resources/business/up.png',
    isDate: false,
    date: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.getSystemInfo({
      success: (res) => {
        //创建节点选择器
        that.setData({
          windowWidth: res.windowWidth
        })
      },
    })
    if(options.type){
      that.setData({
        mainItemType: options.type
      })
    }
    var title = that.getTitle()
    util.setNavBarTitle(title)
    that.setData({
      shopType: app.globalData.shopType,
      urlType: that.getUrl(),
      btnTxt: title,
      startDateImgSrc: that.data.downImg,
      endDateImgSrc: that.data.downImg,
      dateImgSrc: that.data.downImg,
    })
    switch (app.globalData.shopType) {
      case '0':
        type = 'goods'
        that.getMainHeight()
        util.setNavBarTitle(title + '管理')
        //获取商品分类
        util.getAjax(app.globalData.apiUrl +'/get_community_service_shop_product_class',that.getServiceGoodsClass,{shop_id: app.globalData.shopId})
        break;
      case '1':
        util.setNavBarTitle(title + '管理')
        type = 'goods'
        //获取商品分类
        loadMoreView = this.selectComponent("#loadMoreView")
        util.getAjax(app.globalData.apiUrl +'/get_community_health_shop_product_class',that.getGoodsClass,{community_id: app.globalData.communityContent.community_id})
        that.getShopAllData(that.data.classId)//获取商品数据
        break;
      case '2':
        util.setNavBarTitle(title + '管理')
        type = 'kitchen'
        that.getKitchenClass()
        that.getWeek()
        break;
      case '3':
        switch(that.data.mainItemType){
          case 1:
            type = 'property'
            that.getPropertyData()
            break;
          case 2:
            type = 'activity'
            that.getActivities()
            break;
        }
        break;
    }
    
  },

  //获取标题
  getTitle:function(){
    var title = ''
    switch (app.globalData.shopType) {
      case '0':
      case '1':
        title = '商品'
        break;
      case '2':
        title = '菜品'
        break;
      case '3':
        if(this.data.mainItemType == 1){
          title = '物业公告'
        }else{
          title = '活动展示'
        }
        break;
    }
    return title
  },

  //获取url
  getUrl:function(){
    var urlType = ''
    switch (app.globalData.shopType) {
      case '0':
        urlType = 'get_community_service_shop_product';
        break;
      case '1':
        urlType = 'admin_get_health_shop_product';
        break;
      case '2':
        urlType = 'get_community_service_kitchen_product';
        break;
      case '3':
        if(this.data.mainItemType == 1){
          urlType = 'get_community_member_center_property_notice';
        }else{
          urlType = 'get_community_member_center_hd_news';
        }
        break;
    }
    return urlType
  },

  //获取商品分类
  getGoodsClass(res){
    // console.log(res)
    var that = this
    if(res.data.length != 0){
      var navList = []
      for(var i in res.data){
        navList.push(res.data[i])
      }
      let list = that.data.goodsNavList.concat(navList)
      that.setData({
        goodsNavList: list
      })
    }
  },

  //获取商品数据
  getShopAllData:function(classId){
    //获取商品数据
    util.getAjax(`${app.globalData.apiUrl}/${this.data.urlType}`,this.getShopData,{p: p,num: num,class_id: classId,type: 1,like: '',shop_id: app.globalData.shopId},this.shopDataErr)
  },

  getShopData(res){
    var that = this
    console.log(res)
    if(res.data.list.length != 0){
      var list = []
      if(p == 1) {
        list = res.data.list
      } else {
        list = that.data.goodsAllList.concat(res.data.list)
      }
      for(var i in list){
        if(list[i].status){
          var statusTxt = ''
          switch (list[i].status) {
            case '0':
              statusTxt = '申请设为精选'
              break;
            case '1':
              statusTxt = '取消设为精选'
              break;
            case '4':
              statusTxt = '等待审核'
              break;
          }
          list[i].statusTxt = statusTxt
        }
      }
      that.setData({
        goodsAllList: list
      })
    }else{
      that.setData({
        goodsAllList: []
      })
    }
    loadMoreView.loadMoreComplete(res.data,type)
  },

  //获取商品数据异常
  shopDataErr(err){
    if(p>1){
      loadMoreView.loadMoreFail()
    }else{
      util.showModal('提示','获取商品失败，请向上滑动屏幕')
      this.setData({
        isFail: true
      })
    }
  },

  //精选操作
  selectBtn:function(e){
    var that = this
    var mainStatus = e.currentTarget.dataset.status
    var id = e.currentTarget.dataset.id
    if(mainStatus == '4'){
      return
    }
    var text = ''
    var status = ''
    switch (mainStatus) {
      case '0':
        text = '申请设为精选'
        status = '4'    
        break;
      case '1':
        text = '取消设为精选'
        status = '0'    
        break;
    }
    util.postAjax(`${app.globalData.apiUrl}/Api/Communityhealth/save_health_product_one`,function(res){
      // console.log(res)
      if(res.data == 1){
        util.showToast(text + '成功','success',2000)
        that.getShopAllData(that.data.classId)//获取商品数据
      }
    },{id: id,status: status})
  },

  swiperChange:function(e){
    this.setData({
      currentSwiper: e.detail.current
    })
  },

  //选择导航栏
  switchNav(event){
    var that = this
    var cur = event.currentTarget.dataset.current;
    if(that.data.goodsNavList.length > 3){
      //每个tab选项宽度占1/4
      var singleNavWidth = that.data.windowWidth / 4;
      //tab选项居中
      that.setData({
        navScrollLeft: (cur - 1.5) * singleNavWidth
      })
    }else{
      //每个tab选项宽度占1/3
      var singleNavWidth = that.data.windowWidth / 3;
      //tab选项居中
      that.setData({
        navScrollLeft: (cur - 1) * singleNavWidth
      })
    }
    if (that.data.currentGoodsNav == cur) {
      return false;
    } else {
      that.setData({
        currentGoodsNav: cur
      })
      // console.log(that.data.goodsNavList[that.data.currentGoodsNav])
      that.setData({
        classId: that.data.currentGoodsNav != 0?that.data.goodsNavList[that.data.currentGoodsNav].id:'',
      })
      p = 1
      that.getShopAllData(that.data.classId)
    }
  },

  getMainHeight(){
    var that = this;
    var winHeight = '';
    wx.getSystemInfo({
        success(res) {
            // console.log(res.windowHeight)
            winHeight = res.windowHeight;
        }
    })
    var query = wx.createSelectorQuery();
    var topHeight = '';
    query.select('.newGoods').boundingClientRect(rect=>{
        // console.log(rect);
        topHeight = rect.height;
    }).exec();
    setTimeout(function () {
        var mainHeight = winHeight - 70 - topHeight;
        that.setData({
          mainHeight: mainHeight
        })
    },200)
  },

  //获取社区商城商品分类
  getServiceGoodsClass(res){
    console.log(res)
    var that = this
    if(res.data.length != 0){
      that.setData({
        leftNavList: res.data,
        currentId:res.data[0].id
      })
      that.getServiceShopAllData(res.data[0].id)//获取商品数据
    }
  },

  //获取社区商城商品数据
  getServiceShopAllData:function(classId){
    var that = this
    //获取商品数据
    util.getAjax(`${app.globalData.apiUrl}/${that.data.urlType}`,function(res){
      console.log(res)
      if(res.data.length != 0){
        that.setData({
          goodsList: res.data
        })
      }else{
        that.setData({
          goodsList: []
        })
      }
    },{class_id: classId,shop_id: app.globalData.shopId})
  },

  //选择商品类型
  selectItem:function(e){
    var that = this;
    var classId = e.currentTarget.dataset.id;
    that.setData({
      currentId: classId
    })
    that.getServiceShopAllData(classId)
  },

  bindStartDateChange: function(e) {
    this.setData({
      startDate: e.detail.value,
      startDateImgSrc: this.data.downImg,
      isStartDate: true,
      isChangeTime: true
    })
  },

  bindStartDateCancel:function(){
    this.setData({
      startDateImgSrc: this.data.downImg
    })
  },

  bindEndDateChange: function(e) {
    this.setData({
      endDate: e.detail.value,
      endDateImgSrc: this.data.downImg,
      isEndDate: true,
      isChangeTime: true
    })
  },

  bindEndDateCancel:function(){
    this.setData({
      endDateImgSrc: this.data.downImg
    })
  },

  //选择箭头
  imgChange:function(e){
    var that = this
    switch (e.currentTarget.dataset.type) {
      case '开始日期':
        if(that.data.startDateImgSrc == that.data.downImg){
          that.setData({
            startDateImgSrc: that.data.upImg
          })
        }
        break;
    
      case '结束日期':
        if(that.data.endDateImgSrc == that.data.downImg)
        {
          that.setData({
            endDateImgSrc: that.data.upImg
          })
        }
        break;
      case '日期':
        if(that.data.dateImgSrc == that.data.downImg){
          that.setData({
            dateImgSrc: that.data.upImg
          })
        }
        break;
    }
  },

  //删除标签
  startDateDelete:function(){
    this.setData({
      isStartDate: false,
      startDate: '',
      isChangeTime: false
    })
  },

  //删除标签
  endDateDelete:function(){
    this.setData({
      isEndDate: false,
      endDate: '',
      isChangeTime: false
    })
  },

  //特膳厨房分类按钮
  typeBtn:function(e){
    var that = this
    var type = e.currentTarget.dataset.type;
    that.setData({
      mainType: type
    })
    that.getKitchenClass()
  },

  //获取特膳厨房分类
  getKitchenClass:function(){
    var that = this;
    util.getAjax(`${app.globalData.apiUrl}/get_community_service_kitchen_class`,res=>{
        that.setData({
          navList: res.data,
          currentNav: res.data[0].id
        })
        that.getKitchenContent(res.data[0].id)
    },{
      kitchen_id: app.globalData.shopId,
      type: that.data.mainType
    })
  },

  //获取厨房菜单
  getKitchenContent(classId){
    var that = this;
      // console.log(type);
    if(that.data.mainType == 1){
      util.getAjax(`${app.globalData.apiUrl}/${that.data.urlType}`,res=>{
          // console.log(res);
          if(res.data.list.length != 0){
              var list = [];
              if(p == 1){
                  list = res.data.list
              }else{
                  list = that.data.productList.concat(res.data.list)
              }
              that.setData({
                  productList:list
              })
          }else{
            that.setData({
              productList:[]
            })
          }
          loadMoreView = this.selectComponent("#loadMoreView")
          loadMoreView.loadMoreComplete(res.data,type)
      },{
          type: that.data.mainType,
          class_id: classId,
          kitchen_id: app.globalData.shopId,
          num:num,
          p:p
      })
    }else if(that.data.mainType == 2){
      if(that.data.isChangeDate){
        if(that.data.startDate && that.data.endDate){
          that.getTSkitchen(classId,that.data.startDate,that.data.endDate)
        }else{
          util.showToast('请选择时间','none',1000)
        }
      }else{
        if(that.data.navItemCurr == 0){
          // console.log('nav1');
          that.getTSkitchen(classId,that.data.dateInfo.tomorrow,that.data.dateInfo.sunday)
        }else if(that.data.navItemCurr == 1){
          // console.log('nav2');
          that.getTSkitchen(classId,that.data.dateInfo.mondayNext,that.data.dateInfo.sundayNext)
        }
      }
      

    }

  },

  //获取疾病配餐菜单
  getTSkitchen(classId,sTime,eTime){
    // console.log(sTime)
    // console.log(eTime)
    // console.log(classId)
    let that = this;
    util.getAjax(`${app.globalData.apiUrl}/${that.data.urlType}`,res=>{
        // console.log(res);
        if(res.data.list.length != 0){
            var list = [];
            if(p == 1){
                list = res.data.list
            }else{
                list = that.data.productList.concat(res.data.list)
            }
            // console.log(list);
            for(var i in list){
                list[i].week = that.getWeekday(list[i].date)
            }
            //status 1 午餐   2晚餐
            list = that.resetList(list);
            // console.log(list);
            that.setData({
                productList:list
            })
        }else{
            that.setData({
                productList:[]
            })
        }
        loadMoreView = this.selectComponent("#loadMoreView")
        loadMoreView.loadMoreComplete(res.data,type)
    },{
        type: that.data.mainType,
        class_id: classId,
        kitchen_id: app.globalData.shopId,
        num: num,
        p: p,
        start_time: sTime,
        end_time: eTime
    })
  },

  //数组重拼接
  resetList(list){
    let newList = [];
    for(var i=0;i<list.length;i++){
        for(var j=i+1;j<list.length;j++){
            if(list[i].date === list[j].date){
                let temporary = [];
                temporary.push(list[i]);
                temporary.push(list[j]);
                newList.push(temporary)
            }
        }
    }
    for(var a = 0;a<newList.length;a++){
       if(newList[a][0].status != 1){
           let abc = newList[a][0];
           newList[a][0] = newList[a][1];
           newList[a][1] = abc;
       }
    }
    return newList
  },

  //普通膳食导航
  changeNav:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    that.setData({
      currentNav:id,
      productList:[]
    })
    that.getKitchenContent(id);
  },

  //疾病配餐导航
  changeTab:function(e){
    var that = this;
    var id = e.currentTarget.dataset.id;
    that.setData({
        navItemCurr:id,
        productList:[]
    })
    that.getKitchenContent(that.data.currentNav)
  },

  //选择时间段
  changeDate:function(){
    this.setData({
      isChangeDate: true
    })
  },

  //取消选择时间段
  changeDateCancel:function(){
    this.setData({
      isChangeDate: false
    })
    this.getKitchenContent(this.data.currentNav)
  },

  //搜索日期
  searchDate:function(){
    var that = this
    that.getKitchenContent(that.data.currentNav)
  },

  //日期转化为星期
  getWeekday:function(date){
    var date = new Date(date);
    var weekday=new Array(7);
    weekday[0]="星期日"
    weekday[1]="星期一"
    weekday[2]="星期二"
    weekday[3]="星期三"
    weekday[4]="星期四"
    weekday[5]="星期五"
    weekday[6]="星期六"
    var week = weekday[date.getDay()];
    return week
  },

  //获取当前日期周一
  getWeek:function(){
    var that = this;
    var nowTemp = new Date();//当前时间
    var oneDayLong = 24*60*60*1000 ;//一天的毫秒数
    var c_time = nowTemp.getTime() ;//当前时间的毫秒时间
    var c_day = nowTemp.getDay()||7;//当前时间的星期几
    var t_time = c_time + oneDayLong;
    var tomorrow = new Date(t_time);
    var t_year = tomorrow.getFullYear();
    var t_month = (tomorrow.getMonth()+1)>9?(tomorrow.getMonth()+1):'0'+(tomorrow.getMonth()+1);
    var t_date = tomorrow.getDate()>9?tomorrow.getDate():'0'+tomorrow.getDate();
    var m_time = c_time - (c_day-1)*oneDayLong;//当前周一的毫秒时间
    var s_time = c_time + (7-c_day)*oneDayLong;//当前周日的毫秒时间
    var m_next_time = c_time + (8 - c_day)*oneDayLong;//下周周一的毫秒时间
    var s_next_time = c_time + (14 - c_day)*oneDayLong;//下周周日的毫秒时间
    var sunday = new Date(s_time);//设置周日时间对象
    var monday = new Date(m_time);//设置周一时间对象
    var monday_next = new Date(m_next_time);
    var sunday_next = new Date(s_next_time);
    var m_year = monday.getFullYear();
    var s_year = sunday.getFullYear();
    var m_next_year = monday_next.getFullYear();
    var s_next_year = sunday_next.getFullYear();
    var m_month = (monday.getMonth()+1)>10?(monday.getMonth()+1):'0'+(monday.getMonth()+1);
    var s_month = (sunday.getMonth()+1)>10?(sunday.getMonth()+1):'0'+(sunday.getMonth()+1);
    var m_next_month = (monday_next.getMonth()+1)>10?(monday_next.getMonth()+1):'0'+(monday_next.getMonth()+1);
    var s_next_month = (sunday_next.getMonth()+1)>10?(sunday_next.getMonth()+1):'0'+(sunday_next.getMonth()+1);
    var m_date = monday.getDate()>10?monday.getDate():'0'+monday.getDate();
    var s_date = sunday.getDate()>10?sunday.getDate():'0'+sunday.getDate();
    var m_next_date = monday_next.getDate()>10?monday_next.getDate():'0'+monday_next.getDate();
    var s_next_date = sunday_next.getDate()>10?sunday_next.getDate():'0'+sunday_next.getDate();
    that.setData({
        dateInfo:{
            monday:`${m_year}-${m_month}-${m_date}`,
            tomorrow:`${t_year}-${t_month}-${t_date}`,
            sunday:`${s_year}-${s_month}-${s_date}`,
            mondayNext:`${m_next_year}-${m_next_month}-${m_next_date}`,
            sundayNext:`${s_next_year}-${s_next_month}-${s_next_date}`,
        }
    })
  },

  //设置日期
  setDate:function(){
    let dateStart = util.setTime(new Date())
    let Y = dateStart.split('-')
    this.setData({
      dateStart: Y[0]- 3,
      dateEnd: dateStart,
    })
  },

  bindDateChange: function(e) {
    this.setData({
      isDate: true,
      date: e.detail.value,
      dateImgSrc: this.data.downImg
    })
    this.getPropertyData()
  },

  bindDateCancel:function(){
    this.setData({
      dateImgSrc: this.data.downImg
    })
  },

  //删除标签
  DateDelete:function(){
    this.setData({
      isDate: false,
      date: ''
    })
    this.getPropertyData()
  },

  //获取物业公告
  getPropertyData:function(){
    util.getAjax(`${app.globalData.apiUrl}/${this.data.urlType}`,this.getProperty,{type:2,community_id: app.globalData.shopId,date: this.data.date,p: p,num: num},this.getPropertyErr)
  },

  getProperty(res){
    // console.log(res)
    var that = this 
    if(res.data.list.length != 0){
      var list = []
      if(p == 1) {
        list = res.data.list
      } else {
        list = that.data.propertyList.concat(res.data.list)
      }
      that.setData({
        propertyList: list
      })
    }else{
      that.setData({
        propertyList: []
      })
    }
    loadMoreView = this.selectComponent("#loadMoreView")
    loadMoreView.loadMoreComplete(res.data,type)
  },

  //获取物业公告数据异常
  getPropertyErr(err){
    if(p>1){
      loadMoreView.loadMoreFail()
    }else{
      util.showModal('提示','获取物业公告失败，请向上滑动屏幕')
      this.setData({
        isFail: true
      })
    }
  },

  //获取社员中心活动
  getActivities:function(){
    util.getAjax(`${app.globalData.apiUrl}/${this.data.urlType}`,this.getActivity,{community_id: app.globalData.shopId,p: p,num: num},this.getActivityErr)
  },

  getActivity(res){
    console.log(res)
    var that = this 
    if(res.data.list.length != 0){
      var list = []
      if(p == 1) {
        list = res.data.list
      } else {
        list = that.data.activityList.concat(res.data.list)
      }
      that.setData({
        isActivity: true,
        activityList: list
      })
      that.setAllConten(that.data.activityList)
    }else{
      that.setData({
        isActivity: false,
        activityList: []
      })
    }
    loadMoreView = this.selectComponent("#loadMoreView")
    loadMoreView.loadMoreComplete(res.data,type)
  },

  //设置全文
  setAllConten:function(list){
    for(var i in list){
      // console.log(list[i].content.length)
      if(list[i].content.length > 120){
        list[i].isAll = true
        list[i].isClamp = true
        list[i].allTxt = '全文'
        list[i].allSrc = '/resources/mine/down.png'
      }else{
        list[i].isAll = false
        list[i].isClamp = false
      }
    }
    this.setData({
      activityList: list
    })
  },

  //全文折叠
  clampBtn:function(e){
    var that = this
    var id = e.currentTarget.dataset.id
    var list = that.data.activityList
    for(var i in list){
      if(list[i].id == id && list[i].isAll){
        if(list[i].isClamp){
          list[i].isClamp = false
          list[i].allTxt = '收起'
          list[i].allSrc = '/resources/mine/up.png'
        }else{
          list[i].isClamp = true
          list[i].allTxt = '全文'
          list[i].allSrc = '/resources/mine/down.png'
        }
      }
    }
    that.setData({
      activityList: list
    })
  },
  
  //获取商品数据异常
  getActivityErr(err){
    if(p>1){
      loadMoreView.loadMoreFail()
    }else{
      util.showModal('提示','获取活动新闻失败，请向上滑动屏幕')
      this.setData({
        isFail: true
      })
    }
  },

  //点击图片
  imgBtn:function(e){
    // console.log(e)
    var list = e.currentTarget.dataset.list;
    var index = e.currentTarget.dataset.index;
    let arr = []
    for(var i in list){
      arr.push(list[i].url)
    }
    wx.previewImage({
      urls: arr,
      current: arr[index]
    })
  },

  loadMoreListener: function(e) {
    var that = this;
    p += 1
    switch(that.data.shopType){
      case '1':
        that.getShopAllData(that.data.classId)
        break;
      case '2':
        that.getKitchenContent(that.data.currentNav,that.data.kitchenId)
        break;
      case '3':
        if(that.data.mainItemType == 1){
          that.getPropertyData()
        }else{
          that.getActivities()
        }
        break;
    }
  },

  clickLoadMore: function(e) {
    var that = this;
    switch(that.data.shopType){
      case '1':
        that.getShopAllData(that.data.classId)
        break;
      case '2':
        that.getKitchenContent(that.data.currentNav,that.data.kitchenId)
        break;
      case '3':
        if(that.data.mainItemType == 1){
          that.getPropertyData()
        }else{
          that.getActivities()
        }
        break;
    }
  },
  
  //上架新商品
  lickBtn:function(){
    var that = this
    switch(that.data.shopType){
      case '0':
      case '1':
        wx.navigateTo({
          url: '../newGoods/newGoods?type=' + 1,
        })
        break;
      case '2':
        wx.navigateTo({
          url: '../newGoods/newGoods?type=' + 1 + '&mainType=' + that.data.mainType,
        })
        break;
      case '3':
        wx.navigateTo({
          url: '../newGoods/newGoods?type=' + 1 + '&mainItemType=' + that.data.mainItemType,
        })
        break;
    }
  },

  //操作按钮
  operationBtn:function(e){
    var that = this
    var type = e.currentTarget.dataset.type
    var item = e.currentTarget.dataset.item
    if(type == '1'){
      switch(that.data.shopType){
        case '0':
        case '1':
          wx.navigateTo({
            url: '../newGoods/newGoods?type=' + 2 + '&item=' + JSON.stringify(item),
          })
          break;
        case '2':
          wx.navigateTo({
            url: '../newGoods/newGoods?type=' + 2 + '&mainType=' + that.data.mainType + '&id=' + e.currentTarget.dataset.id,
          })
          break;
        case '3':
          wx.navigateTo({
            url: '../newGoods/newGoods?type=' + 2 + '&item=' + JSON.stringify(item) + '&mainItemType=' + that.data.mainItemType,
          })
          break;
      }
      //编辑
    }else if(type == '2'){
      //下架
      var id = e.currentTarget.dataset.id
      var urlType = ''
      var text = ''
      switch (that.data.shopType) {
        case '0':
          urlType = 'admin_operation_community_service_shop_product'
          text = '商品'
          break;
        case '1':
          urlType = 'admin_operation_community_health_shop_product'
          text = '商品'
          break;
        case '2':
          urlType = 'operation_community_service_kitchen_product'
          text = '菜品'
          break;
        case '3':
          if(that.data.mainItemType == 1){
            urlType = 'admin_operation_community_member_center_property_notice'
            text = '物业公告'
          }else{
            urlType = 'operation_community_member_center_hd_news'
            text = '活动展示'
          }
          break;
      }
      util.showModelAll('提示','是否确定删除该'+ text,function(){
        util.postAjax(`${app.globalData.apiUrl}/${urlType}`,function(res){
          console.log(res)
          if(res.data == 1){
            util.showToast(text + '删除成功','success',2000)
            switch (that.data.shopType) {
              case '0':
                that.getServiceShopAllData(that.data.currentId)
                break;
              case '1':
                that.getShopAllData(that.data.classId)
                break;
              case '2':
                that.getKitchenContent(that.data.currentNav)
                break;
              case '3':
                if(that.data.mainItemType == 1){
                  that.getPropertyData()
                }else{
                  that.getActivities()
                }
                break;
            }
          }else{
            util.showModal('提示','删除失败，请重试')
          }
        },{
          type: 3,
          id: id
        })
      })
    }
  },

  //回到顶部
  goTop: function (e) {
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },

  // 获取滚动条当前位置
  onPageScroll: function (e) {
    // console.log(e)
    if (e.scrollTop > 600) {
      this.setData({
        isTop: true
      });
    } else {
      this.setData({
        isTop: false
      });
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    if(that.data.urlType){
      switch (app.globalData.shopType) {
        case '0':
          if(that.data.currentId){
            that.getServiceShopAllData(that.data.currentId)
          }
          break;
        case '1':
          that.getShopAllData(that.data.classId)
          break;
        case '2':
          if(that.data.currentNav){
            that.getKitchenContent(that.data.currentNav)
          }
          break;
        case '3':
          if(that.data.mainItemType == 1){
            that.getPropertyData()
          }else{
            that.getActivities()
          }
          break;
      }
    }
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    if(that.data.shopType != '0'){
      if(that.data.isFail){
        switch(that.data.shopType){
          case '1':
            that.getShopAllData(that.data.classId)
            break;
          case '2':
            that.getKitchenContent(that.data.currentNav,that.data.kitchenId)
            break;
          case '3':
            if(that.data.mainItemType == 1){
              that.getPropertyData()
            }else{
              that.getActivities()
            }
            break;
        }
        return
      }
      loadMoreView.loadMore()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
